#include "stdafx.h"
#include "ApkButtonEx.h"
#include "Log.h"

CApkButtonEx::CApkButtonEx()
{
	mBtnState = APK_BTN_STATE_NORMAL;
	mIsUserClickBtn = FALSE;
	mExtFirstCfg = FALSE;
	mExtSecondCfg = FALSE;
}

CApkButtonEx::~CApkButtonEx()
{
}

BOOL CApkButtonEx::Init(CDialog *dlg, int buttonID)
{
	log_printf("CApkButtonEx::init buttonID=%d\n", buttonID);
	mPDlg = dlg;
	mResourceID = buttonID;
	mBtnWnd = mPDlg->GetDlgItem(buttonID);

	return TRUE;
}

void CApkButtonEx::SetState(int state)
{
	mBtnState = state;
}

int CApkButtonEx::GetState()
{
	return mBtnState;
}

void CApkButtonEx::SetUserConfirmItem(int userConfirm)
{
	mIsUserClickBtn = userConfirm;
}

BOOL CApkButtonEx::GetUserConfirmItem()
{
	return mIsUserClickBtn;
}

CString CApkButtonEx::GetStateString()
{
	if (GetState() == APK_BTN_STATE_PASS)
	{
		return "PASS";
	}
	else
	{
		return "NG";
	}
}

int CApkButtonEx::SwitchTestResultState()
{
	if (GetState() != APK_BTN_STATE_PASS)
	{
		SetState(APK_BTN_STATE_PASS);
		SetWindowText("PASS");
	}
	else
	{
		SetState(APK_BTN_STATE_NG);
		SetWindowText("NG");
	}
	return GetState();
}

void CApkButtonEx::SetWindowText(CString info)
{
	mBtnWnd->SetWindowText(info);
}

void CApkButtonEx::Reset()
{
	mBtnState = APK_BTN_STATE_NORMAL;
	if (mIsUserClickBtn)
	{
		SetWindowText(APK_TEST_BTN_STATE_WAIT_FOR_TEST_TIP_USER);
	}
	else
	{
		SetWindowText(APK_TEST_BTN_STATE_WAIT_FOR_TEST_TIP);
	}

	mExtFirstCfg = FALSE;
	mExtSecondCfg = FALSE;
}

CString CApkButtonEx::GetErrorCode()
{
	CString temp;
	temp.Format("E%d", mResourceID);
	return temp;
}

int CApkButtonEx::GetBgColor()
{
	switch (mBtnState)
	{
	case APK_BTN_STATE_NG:
		return RGB(255, 0, 0);
	case APK_BTN_STATE_PASS:
		return RGB(0, 255, 0);
	case APK_BTN_STATE_NORMAL:
		if (mIsUserClickBtn)
		{
			return RGB(255,127,80);
		}
		else
		{
			return RGB(236, 233, 216);
		}
	}
}

int CApkButtonEx::GetResourceID()
{
	return mResourceID;
}

BOOL CApkButtonEx::IsTestFinish()
{
	if (mBtnState == APK_BTN_STATE_NORMAL)
	{
		return FALSE;
	}

	return TRUE;
}

void CApkButtonEx::ShowWindow(BOOL isShow)
{
	mBtnWnd->ShowWindow(isShow);
}

void CApkButtonEx::SetExtFirstCfgItem(BOOL isCfg)
{
	mExtFirstCfg = isCfg;
}

void CApkButtonEx::SetExtSecondCfgItem(BOOL isCfg)
{
	mExtSecondCfg = isCfg;
}

BOOL CApkButtonEx::GetExtFirstCfgItem()
{
	return mExtFirstCfg;
}

BOOL CApkButtonEx::GetExtSecondCfgItem()
{
	return mExtSecondCfg;
}